﻿using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using NHibernate;
using NHibernate.Cfg;
using System.Text.RegularExpressions;
using System.Collections.Generic;


/// <summary>
/// Control de datos de la entidad pagos.
/// </summary>
/// 
public class PagoControl
{
	public PagoControl()
	{

	}

    /// <summary>
    /// Funcion para devolver todos los pagos registrados
    /// </summary>
    /// <returns>pagos</returns>
    /// 
        public IList GetPagos()
    {
        IList pagos = null;
        ISession session = NHibernateControl.GetCurrentSession();
        try
        {
            ITransaction tx = session.BeginTransaction();
            pagos = session.CreateCriteria(typeof(Pago)).List();
            session.Flush();
            NHibernateControl.CloseSession();
        }
        catch (NHibernate.TransactionException a) {
            Console.Write(a.Message);
        }
        return pagos;
    }

        /// <summary>
        /// Funcion para devolver todos los pagos de una factura
        /// </summary>
        /// <param name="idFactura">id de factura</param>
        /// <returns>pagosfactura</returns>
        ///
        public IList PagosFactura(int idFactura)
        {
            IList Pagos = this.GetPagos();
            IList pagosfactura = new ArrayList(); 

            if (Pagos != null)
            {
                foreach (Pago pagosfac in Pagos)
                {
                    if (pagosfac.Factura.Id == idFactura)
                        pagosfactura.Add(pagosfac);
                }
            }
           return pagosfactura;
        }

}
